import { useEffect, useState } from "react";

export const usePresskeyborad = () => {
  const [keys, setKeys] = useState<string[]>([]);
  useEffect(() => {
    document.onkeydown = (e) => {
      e.stopPropagation();
      if (!keys.includes(e.key)) {
        keys.push(e.key);
        setKeys(keys.slice());
      }
    };
    document.onkeyup = (e) => {
      keys.splice(keys.indexOf(e.key), 1);
      setKeys(keys);
    };
    return () => {
      document.onkeydown = null;
      document.onkeyup = null;
    };
  }, []);
  return {
    keys,
  };
};
